// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init()

/**
 * event参数说明
 * @param {Number} skip 跳过多少记录
 * @param {String} type 记录类型，idea、team或article
*/
// 云函数入口函数
exports.main = async (event, context) => {
  var skip = event.skip;
  var type = event.type;
  const db = cloud.database();
  var res = await db.collection('post').aggregate()
    .lookup({
      from: 'user',
      localField: '_openid',
      foreignField: '_openid',
      as: 'owner'
    })
    .match({
      type: type
    })
    .skip(skip)
    .limit(25)
    .end();
    console.log('get team list', res);
    return res.list;
}